package com.mysoft.gfyx.marketdevelop.controller.tag;

import com.mysoft.framework.modeling.dto.OptionItem;
import com.mysoft.framework.mvc.api.Controller;
import com.mysoft.framework.rpc.annotation.PubAction;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.framework.sdk.system.api.SystemDataProvider;
import com.mysoft.gfyx.marketdevelop.controller.dto.CreditCodeBaseRequestDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.tag.AreaDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.tag.GetAllOptionsRequestDto;
import com.mysoft.gfyx.marketdevelop.service.DeveloperService;
import com.mysoft.gfyx.marketdevelop.service.LabelService;
import com.mysoft.gfyx.marketdevelop.service.ProvinceAndCityService;
import com.mysoft.gfyx.marketdevelop.service.dto.ProvinceAndCityConditionDto;
import com.mysoft.gfyx.marketdevelop.service.dto.ProvinceAndCityDto;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.*;

@PubService(value = "/optionsPub", prefix = RequestPrefix.PUB)
public class OptionsPubController extends Controller {

    @Resource
    private LabelService labelService;

    @Resource
    private ProvinceAndCityService provinceAndCityService;

    @Resource
    private SystemDataProvider systemDataProvider;

    @PubAction(value = "/getAllOptions")
    public Map<String, List<OptionItem>> getAllOptions(@RequestBody GetAllOptionsRequestDto dto) {
        List<String> tags = dto.getTags();
        Map<String, List<OptionItem>> allDictionaries = new HashMap<>();

        if (tags.contains("Area")) {
            List<OptionItem> items = new ArrayList<>();
            List<ProvinceAndCityDto> res = provinceAndCityService.getAllWithParent();

            res.forEach(areaDto -> {

                OptionItem item = new OptionItem();
                item.setValue(areaDto.getItemCode());
                item.setParent(areaDto.getParentCode());
                item.setText(areaDto.getItemName());

                items.add(item);
            });

            allDictionaries.put("Area", items);
        }

        if (tags.contains("CompanyType")) {
            allDictionaries.put("CompanyType", labelService.loadValueTo0ValueTagsByTagName(DeveloperService.TjEntity.Developer, LabelService.LABEL_COMPANY_TYPE));
        }

        if (tags.contains("LandType")) {
            allDictionaries.put("LandType", labelService.loadValueTo0ValueTagsByTagName(DeveloperService.TjEntity.Developer, LabelService.LABEL_LAND_TYPE));
        }

        if (tags.contains("ProjectType")) {
            allDictionaries.put("ProjectType", labelService.loadValueTo0ValueTagsByTagName(DeveloperService.TjEntity.Developer, LabelService.LABEL_PROJECT_TYPE));
        }

        if (tags.contains("ProjectFitmentType")) {
            allDictionaries.put("ProjectFitmentType", labelService.loadValueTo0ValueTagsByTagName(DeveloperService.TjEntity.Developer, LabelService.LABEL_FITMENT_TYPE));
        }

        if (tags.contains("DeveloperSmartTag")) {
            allDictionaries.put("DeveloperSmartTag", labelService.DeveloperSmartTag());
        }

        if (tags.contains("DeveloperTag")) {
            allDictionaries.put("DeveloperTag", labelService.DeveloperTag());
        }

        if (tags.contains("Activity")) {
            allDictionaries.put("Activity", labelService.loadValueTo0ValueTagsByTagName(DeveloperService.TjEntity.Developer, LabelService.LABEL_ACTIVITY));
        }

        if (tags.contains("PublishTime")) {
            List<OptionItem> options = new LinkedList<>();
            OptionItem item7 = new OptionItem();
            item7.setValue("最近7天");
            item7.setText("最近7天");
            options.add(item7);
            OptionItem item30 = new OptionItem();
            item30.setValue("最近30天");
            item30.setText("最近30天");
            options.add(item30);
            OptionItem quarter = new OptionItem();
            quarter.setValue("本季度");
            quarter.setText("本季度");
            options.add(quarter);
            OptionItem year = new OptionItem();
            year.setValue("本年");
            year.setText("本年");
            options.add(year);
            allDictionaries.put("PublishTime", options);
        }
        //拿地、开盘时间选择项
        if (tags.contains("LandDateOption")) {
            List<OptionItem> options = new LinkedList<>();
            OptionItem item7 = new OptionItem();
            item7.setValue("本年");
            item7.setText("本年");
            options.add(item7);
            OptionItem item30 = new OptionItem();
            item30.setValue("最近3年");
            item30.setText("最近3年");
            options.add(item30);
            OptionItem quarter = new OptionItem();
            quarter.setValue("最近6年");
            quarter.setText("最近6年");
            options.add(quarter);
            allDictionaries.put("LandDateOption", options);
        }

        if (tags.contains("BidType")) {
            List<OptionItem> options = new LinkedList<>();
            OptionItem ycg_bid = new OptionItem();
            ycg_bid.setValue("ycg_bid");
            ycg_bid.setText("平台招标");
            options.add(ycg_bid);
            OptionItem ycg_recruit = new OptionItem();
            ycg_recruit.setValue("ycg_recruit");
            ycg_recruit.setText("平台招募");
            options.add(ycg_recruit);
            OptionItem website_bid = new OptionItem();
            website_bid.setValue("website_bid");
            website_bid.setText("官网招标");
            options.add(website_bid);
            OptionItem trading_center = new OptionItem();
            trading_center.setValue("trading_center");
            trading_center.setText("公共交易中心");
            options.add(trading_center);
            allDictionaries.put("BidType", options);
        }

        //业务参数:线索状态，scopeId来源myparamvalue表
        //https://open.mingyuanyun.com/docs/platform/latest/SDK/%E5%90%8E%E7%AB%AFSDK/JAVA%20SDK/API/%E5%BB%BA%E6%A8%A1System%20api
        if (tags.contains("ClueCooperationStatus")) {
            List<OptionItem> clueCooperationStatus = systemDataProvider.getParamValueOfOption("4022", "clue_cooperation_status", "11b11db4-e907-4f1f-8835-b9daab6e1f23");
            allDictionaries.put("ClueCooperationStatus", clueCooperationStatus);
        }

        //业务参数:线索状态，scopeId来源myparamvalue表
        if (tags.contains("ClueContactWay")) {
            List<OptionItem> clueCooperationStatus = systemDataProvider.getParamValueOfOption("4022", "clue_contactWay", "11b11db4-e907-4f1f-8835-b9daab6e1f23");
            allDictionaries.put("ClueContactWay", clueCooperationStatus);
        }

        //土地：土地类型、用途
        if (tags.contains("LandUsage")) {
            allDictionaries.put("LandUsage", labelService.loadValueTagsLandType(0));
        }

        //在建项目:工程用途
        if (tags.contains("ProjectFunction")) {
            allDictionaries.put("ProjectFunction", labelService.loadValueTagsPrjFunction(1));
        }

        //行业分类
        if (tags.contains("IndustryOptions")) {
            allDictionaries.put("IndustryOptions", labelService.loadValueTagsIndustry());
        }

        return allDictionaries;
    }
}
